//
//  BaseViewController.swift
//  test
//
//  Created by jyvyi_ios on 2022/4/26.
//

import UIKit

class BaseViewController: UIViewController {
    
    override func loadView() {
        super.loadView()
        
        self.setLayoutMargins()
        
        if #available(iOS 11.0, *) {
            //计算上safeInsets
            self.view.insetsLayoutMarginsFromSafeArea = true
        }
        //是否受父类margins约束
        self.view.preservesSuperviewLayoutMargins = false
    }
    
    func setLayoutMargins(){
        
        var tabBarHeight : CGFloat = 0
        var navigationHeight : CGFloat = 0
        
        if let tabBarController = self.tabBarController as? BaseTabBarViewController{
            tabBarHeight = tabBarController.customTabBarHeight
        }
        if let navigationController = self as? BaseNavigationBarViewController{
            navigationHeight = navigationController.customNavigationBarHeight
        }
        //自定义layoutMargins
        self.view.layoutMargins = UIEdgeInsets.init(top: navigationHeight, left: 0, bottom: tabBarHeight, right: 0)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        // 标记被present出来时候，防止preferredStatusBarStyle属性被忽略
        self.modalPresentationCapturesStatusBarAppearance = true
        
        if #available(iOS 11.0, *) {
            UIScrollView.appearance().contentInsetAdjustmentBehavior = .never
        } else {
            self.automaticallyAdjustsScrollViewInsets = false
        }
    }
}
